package com.ts.main.mini.controller;

import com.ts.main.mini.dto.ProductSearchDto;
import com.ts.main.mini.dto.ProductSearchPageDto;
import com.ts.main.mini.exception.R;
import com.ts.main.mini.exception.RPage;
import com.ts.main.mini.service.ProductServiceImpl;
import com.ts.main.mini.vo.ProductVariantVo;
import com.ts.main.mini.vo.ProductVo;
import com.ts.main.mini.vo.ProductDetailsToCartVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 小程序-商品管理
 * @Author:lk
 * @Date: 2025/5/18  03:41
 */
@AllArgsConstructor
@RestController
@RequestMapping("/mini/product")
@Tag(name = "小程序-商品管理")
public class ProductController {

    private final ProductServiceImpl productService;


    /**
     * 查询商品列表（分页查询）
     * @return
     */
    @Operation(summary = "查询商品列表（分页查询）")
    @PostMapping("/getProductPage")
    public RPage<List<ProductVo>> getProductPage(@RequestBody ProductSearchPageDto dto){
        return productService.getProductPage(dto);
    }

    /**
     * 查询商品列表
     * @return
     */
    @Operation(summary = "查询商品列表")
    @PostMapping("/getProductList")
    public R<List<ProductVo>> getProductList(@RequestBody ProductSearchDto dto){
        return R.ok(productService.getProductList(dto));
    }


    /**
     * 查询商品详情
     * @return
     */
    @Operation(summary = "查询商品详情")
    @GetMapping("/getProductDetails")
    public R<ProductVo> getProductDetails(@Schema(description = "商品ID") @RequestParam("productId") Integer productId){
        return R.ok(productService.getProductDetails(productId));
    }


    /**
     * 查询商品的选项和选项值
     * @return
     */
    @Operation(summary = "查询商品的选项和选项值")
    @GetMapping("/getProductDetailsToCart")
    public R<ProductDetailsToCartVo> getProductDetailsToCart(@Schema(description = "商品ID") @RequestParam("productId") Integer productId){
        return R.ok(productService.getProductDetailsToCart(productId));
    }


    /**
     * 查询商品组合价格和库存
     * @return
     */
    @Operation(summary = "查询商品组合的价格和库存（sku）")
    @GetMapping("/getProductCombination")
    public R<ProductVariantVo> getProductCombination(@Schema(description = "商品ID") @RequestParam("productId") Integer productId,
                                                     @Schema(description = "商品组合信息") @RequestParam("optionCombination") String optionCombination){
        return R.ok(productService.getProductCombination(productId,optionCombination));
    }

}
